#include <iostream>
#include <unistd.h>

using namespace std;

typedef void(*work_t)();
typedef void(*task_t)();

void task1()
{
    cout << "task1" << endl;
}

void task2()
{
    cout << "task2" << endl;
}

void task3()
{
    cout << "task3" << endl;
}

task_t tasks[3] = {task1, task2, task3};

void worker()
{
    while(1)
    {
        int work_code = 0;
        int read_return_value = read(0, &work_code, sizeof(work_code));

        if(read_return_value == sizeof(work_code))
        {
            if(work_code >= 3) continue;
            tasks[work_code]();
        }

        sleep(1);
    }
}